package com.aaa.boot.utils;

import org.apache.http.HttpResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @author MK
 * @version 1.0
 * 创建时间：2025/4/1 14:51
 */
public class MsgUtil {
    public static String SendMsg(String phone, String code){
        String host = "https://send.market.alicloudapi.com";
        String path = "/sms/send";
        String method = "POST";
        String appcode = "c8901a2a2b51460fa04b2371a2b8dc5e";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("content", "code:"+code);
        bodys.put("templateid", "lxym_20111_sdgsfhwqgvyh");
        bodys.put("mobile", phone);


        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return code;
    }
}
